﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HSDc.RingleFlow.Api.Rule;
using HSDc.RingleFlow.Api.Kernel;

namespace HSDc.RingleFlow.Kernel
{
    internal class Swimlane
    {
        private IRule _Rule;
        private string _ID;
        private int? _OrgID;
        private SwimlaneType _Type;

        internal Swimlane(string _ID, int? _OrgID, SwimlaneType _Type, IRule _Rule)
        {
            this._ID = _ID;
            this._OrgID = _OrgID;
            this._Type = _Type;
            this._Rule = _Rule;
        }

        internal string DecideAssignee(Dictionary<string, object> variables)
        {
            if (_OrgID != null)
            {
                if (variables.ContainsKey("OrgID"))
                    variables.Remove("OrgID");
                variables.Add("OrgID", _OrgID);
            }
            string assignee = _Rule.Execute(variables);
            if (_Type == SwimlaneType.Department) assignee = "dept|" + assignee;
            return assignee;
        }
    }
}
